﻿<%--
 *  File:    VisitPlanAddPop.jsp
 *  @Author: KentZhong 
 *  Date:    2009-10-9 10:02:44
 *
 *  Copyright (C) 2000 - 2009 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>
<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>


<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>


<%

  String strTableName = "v_visitplancustomer";
  String strModuleName = "SFE";
  String contextPath = request.getContextPath();
  java.util.HashMap userInfo = (java.util.HashMap)session.getAttribute("userinfo"); 
%>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>
<html>
<head>
<title><%=label.getLabelName("L_Add")%></title>
<%
if("Y".equals(request.getParameter("isconfirm"))){%>

%>
<script>
	opener.refreshWindow();
</script>
<%return;
}%>	
<PageFlow:CheckPageFlow pageName="p_visitplanaddpop"/>
<%@ include file="/inc/SumDiv.inc" %>
<%
int nYear=((Integer)pageContext.getAttribute("year")).intValue();
int nMonth=((Integer)pageContext.getAttribute("monthofyear")).intValue();
int nWeek=((Integer)pageContext.getAttribute("weekofmonth")).intValue();
int nDay=((Integer)pageContext.getAttribute("dayofweek")).intValue();
Date dStartDate=(Date)pageContext.getAttribute("weekstart");
Calendar cal=null;
if(nYear>0 && nMonth>0 && nWeek>0)
{
	cal=Calendar.getInstance();
	cal.clear();
	cal.setFirstDayOfWeek(Calendar.MONDAY);
	cal.setTime(dStartDate);
	cal.add(Calendar.DATE,nDay-1);
 }
 nYear=cal.get(Calendar.YEAR);
 nMonth=cal.get(Calendar.MONTH)+1;
 nWeek=cal.get(Calendar.WEEK_OF_MONTH);
 nDay=cal.get(Calendar.DAY_OF_WEEK);
 pageContext.setAttribute("year",new Integer(nYear));
 pageContext.setAttribute("monthofyear",new Integer(nMonth));
 pageContext.setAttribute("weekofmonth",new Integer(nWeek));
 //pageContext.setAttribute("dayofweek",new Integer(nDay));
java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("yyyy-MM-dd");
String strVisitDate=sdf.format(cal.getTime());
java.text.SimpleDateFormat sdfVisit=new java.text.SimpleDateFormat((String)session.getAttribute("dateformat"));
String strVisitDateShow=sdfVisit.format(cal.getTime());
%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath%>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/ScriptLib.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/SummaryDivision.js"></script>
<script language="JavaScript">
<%--  put your custom script here   --%>
function page_summary(actionvalue,orderbyname)
{
  var editform = summaryPrepare(cform,actionvalue,orderbyname);
  if(!editform) return;
  editform.action = "VisitPlanAddPop.jsp?<%= OvalTools.randomURL() %>";
  editform.target = "_self";
  isRunning = true;
  editform.submit();
}
function page_cancel()
{
	window.close();
}
function page_confirm()
{
	var myform = eval("document.cform");
	var details=eval("document.cform.customerids");
	
	
	if(isNullChecked(details))
  {
    alert("<%= message.getMessageDesc("MUST_SELECT_ONE_RECORD_TO_ADD") %>");
    return;
  }
  for(i=0;i<Number(myform.numrows.value);i++)
  {
  	var customer=eval("myform.customerid"+i);
  	var checkids=eval("myform.chkids"+i);
  	var processid=eval("myform.processid"+i);
  	var uprocessid=eval("myform.uprocessid"+i);
  	var sstart=eval("myform.splanstarttime"+i);
		var send=eval("myform.splanendtime"+i);
		var tsstart=eval("myform.tsplanstarttime"+i);
		var tsend=eval("myform.tsplanendtime"+i);
		
		var dvisit=eval("myform.planvisitdate"+i);
		
  	if(!checkids.checked)
  	{
  		customer.value=" ";
  	}
  	else
  	{
  		<%--if(isEmpty(tsstart.value))
			{
				alert("<%=message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_VisitPlanStartTime"))%>");
				return;
			}
			if(isEmpty(tsend.value))
			{
				alert("<%=message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_VisitPlanEndTime"))%>");
				return;
			}
			if(!isTime(tsstart.value,"HH:mm"))
			{
				alert("<%=message.getMessageDesc("ILLEGAL_FORMAT",label.getLabelName("L_VisitPlanStartTime"))%>(HH:mm)");
				return;
			
			}
			if(!isTime(tsend.value,"HH:mm"))
			{
				alert("<%=message.getMessageDesc("ILLEGAL_FORMAT",label.getLabelName("L_VisitPlanEndTime"))%>(HH:mm)");
				return;
			
			}--%>
  		customer.value=checkids.value;
  		if(isEmpty(processid.value) && isEmpty(uprocessid.value)){
  		   alert("<%=message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_VisitProcess"))%>");
  		   return;
  		}
  		//sstart.value=dvisit.value+" "+tsstart.value+":00";
		//	send.value=dvisit.value+" "+tsend.value+":00";
  	}
  	
  }
  myform.actionname.value = "add";
 	myform.target="_self";
 	isRunning = true;
 	myform.submit();
}	
function page_needassist(seq)
{
	var myform = eval("document.cform");
	var sneedassist=eval("myform.showneedassist"+seq);
	var needassist=eval("myform.needassist"+seq);
	var div = document.getElementById("assistdiv"+seq); 
	if(sneedassist.checked)
	{
		needassist.value="Y";

		div.style.display = 'block';
	}
	else{
		needassist.value="N";
		div.style.display = 'none';
	}
}
function page_setUser(id,code,name){
	var rownum= document.cform.rownum.value;
	eval("document.cform.assistuserid"+rownum).value=id;
	eval("document.cform.assistemployeename"+rownum).value=name;
}

function page_selectUser(num) {
        document.cform.rownum.value=num;
        //alert(eval("document.cform.assistuserid"+num).value);
		var status = "height=400, width=600,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no";
		var url = "<%=contextPath%>/sfe/UserSelectPop.jsp?businessareaid="+<%=userInfo.get("businessareaid")%>+"&contactid=<custom:write property="contactid"/>"+"&o_thread=" + Math.random();
			
		if (typeof popwindow != 'undefined') popwindow.close();
		popwindow = window.open(url, "newwindow2", status);
    }
</script>
</head>
<body style="overflow: auto;">
	<form name="cform" method="post" action="<%=contextPath%>/Dispatcher">
    <input type="hidden" name="pagename" value="p_visitplanaddpop">
    <input type="hidden" name="actionname">
    <input type="hidden" name="rownum">
    <custom:hidden property="contactid"/>
    <custom:hidden property="orgid"/>
    <custom:hidden property="year"/>
    <custom:hidden property="monthofyear"/>
    <custom:hidden property="weekofmonth"/>
    <custom:hidden property="dayofweek"/>
    <custom:hidden property="ishistory"/>	
    <custom:hidden property="visitplanid" />
    <custom:hidden property="weekstart"/>
    <custom:hidden property="weekend" />	
     <custom:hidden property="activitytype" />	
    <custom:hidden property="weekstartweekofmonth" />	
    <input type="hidden" name="removedempty" value=" "/>	
   <table width="100%" cellspacing="0" border="0" cellpadding="0">
      <tr>
<%--  search criteria  --%>
      </tr>
      <tr>
        <td>
          
          <table width="100%" border="0" cellspacing="0">
           
            <%@ include file="/inc/SummarySearch.inc" %>
            
            
          </table>
        </td>
      </tr>
      <tr>
        <td>
          <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
             <tr class="deepblue-left"> 
          			<td class="title_center" width="22">&nbsp;</td>
          			<td class="title_center" width="60"><%=label.getLabelName("L_CustomerCode")%></td>
          			<td class="title_center" ><%=label.getLabelName("L_CustomerName")%></td>
          			<td class="title_center" width="50"><%=label.getLabelName("L_OrgPCName")%></td>
          			<td class="title_center" width="100"><%=label.getLabelName("L_CustomervisitProgram")%></td>
          			<td class="title_center" width="100"><%=label.getLabelName("L_PeoplevisitProgram")%></td>
          			<td class="title_center" width="80"><%=label.getLabelName("L_VisitPlanDate")%></td>
          			<td class="title_center" width="50"><%=label.getLabelName("L_LastVisitDate")%></td>
          			<td class="title_center" width="50"><%=label.getLabelName("L_CountVisitOfMonth")%></td>
          			<td class="title_center" width="50"><%=label.getLabelName("L_NeedAssist")%></td>
          			<td class="title_center" width="10%"><%=label.getLabelName("L_AssistUser")%></td>
          			
          	</tr>
          	<%
          		Vector vCustomers=(Vector)pageContext.getAttribute("customers");
          		if(vCustomers==null)
          			vCustomers=new Vector();
          		String strClassType = "none";	
          		
          	%>
          	 <logic:iterate id="customerinfo" collection="<%=vCustomers%>" indexId="idx">
          	 	<%
          	 	int seq=((Integer)pageContext.getAttribute("idx")).intValue();
          	 	 if(seq%2 == 1)
            {
              strClassType = "td-listrom";
            }else{
              strClassType = "none";
            }
          	 	%>
          	 	<!--  <tr onMouseOver="this.className='tr-over'" onMouseOut="this.className='<%=strClassType%>'"   class="<%=strClassType%>" >-->
          	 	<tr class="<%=strClassType%>" >
	 					  	<td>
	 					  		<input type="checkbox" name="customerids" id="chkids<%=seq%>" value="<custom:write name="customerinfo" property="orgid"/>" class="normalradio"/>
	 					  		<custom:hidden name="customerinfo"	 property="orgid" changedName="customerid" colIndex="<%=idx%>"/>	
	 					  		<input type="hidden" name="planvisitdate<%=seq%>"	value="<%=strVisitDate%>"/>
	 					  		<input type="hidden" name="splanstarttime<%=seq%>" value="<%=strVisitDate%>"/>		
									<input type="hidden" name="splanendtime<%=seq%>" value="<%=strVisitDate%>"/>	
									
	 					  	</td>
	 					  	<td><custom:write name="customerinfo"	 property="orgcode"/></td>
	 					  	<td><custom:write name="customerinfo"	 property="orgname"/></td>
	 					  	<td><custom:write name="customerinfo"	 property="globalpcname"/></td>
	 					  	<td>
	 					  	<custom:select  name="customerinfo"	 property="processid"   optionsName="customprocesses" optionValueKey="visitprocessid" optionInnerTextKey="processname"  colIndex="<%=idx%>" defaultValue="---" defaultValueCost=" " />
	 					  	</td>
	 					  	<td>
	 					  	<custom:select  name="customerinfo"	 property="uprocessid"   optionsName="doctorprocesses" optionValueKey="visitprocessid" optionInnerTextKey="processname"  colIndex="<%=idx%>" defaultValue="---" defaultValueCost=" " />
	 					  	</td>
	 					  	<td class="td_right"><%=strVisitDateShow%></td>
	 					  	<td><custom:write name="customerinfo" property="lastvisitdate" nbsp="true" /></td>
							<td><custom:write name="customerinfo" property="count_org" nbsp="true" /></td>
								<td>
							 <input type="checkbox"  name="showneedassist<%=seq%>"  class="normalradio"  onclick="javascript:page_needassist('<%=seq%>')">
						     <custom:hidden name="customerinfo" property="needassist" colIndex="<%=Integer.valueOf(seq)%>"/>
								</td>
							<td>&nbsp;<div id="assistdiv<%=seq%>" >
							 <custom:text name="customerinfo" property="assistemployeename" size="10" colIndex="<%=Integer.valueOf(seq)%>" />
							 <a onclick="javascript:page_selectUser(<%=seq%>);">
							 <custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0" />
							 <custom:hidden name="customerinfo" property="assistuserid" colIndex="<%=Integer.valueOf(seq)%>"/>
							 </a>
							 </div>
							 </td>	
	 					  </tr>
          	 </logic:iterate>
          	<%@ include file="/inc/SummaryAction.inc" %>
          </table>
          <input type="hidden" name="numrows" value="<%=vCustomers.size()%>"/>
        </td>
      </tr>
      <tr>
      	<td>
      		<table width="100%" cellspacing="0" cellpadding="0">
            <tr><td class="summary_top"></td></tr>
            <tr>
              <td class="td_center">
             <a onclick="page_confirm();"><custom:button type="1" label="L_Confirm" imgsrc="new.gif" border="0" style="width:60"/></a>
                
                <a onclick="page_cancel();"><custom:button type="1" label="L_Cancel" imgsrc="Modify.gif" border="0" style="width:60"/></a>
                
               
              </td>
            </tr>
          </table>  
        </td>
      </tr>
    </table>
  </form>  
  <script>
  <%
  java.util.HashMap parentuserinfo = (java.util.HashMap)pageContext.getAttribute("parentuserinfo"); 
  %>
  for(var i=0;i<<%=vCustomers.size()%>;i++){
    if(eval("document.cform.needassist"+i).value=="Y"){
        var div = document.getElementById("assistdiv"+i); 
		div.style.display = 'block';
		<%
		if (parentuserinfo!=null) {
		%>
		 if(isEmpty(eval("document.cform.assistuserid"+i).value)){
		  eval("document.cform.assistuserid"+i).value="<%=parentuserinfo.get("assistuserid")%>";
		  eval("document.cform.assistemployeename"+i).value="<%=parentuserinfo.get("assistemployeename")%>";
		 }
		<%
		}
	    %>
    }else{
        var ndiv = document.getElementById("assistdiv"+i); 
		ndiv.style.display = 'none';
		<%
		if (parentuserinfo!=null) {
		%>
		 if(isEmpty(eval("document.cform.assistuserid"+i).value)){
		  eval("document.cform.assistuserid"+i).value="<%=parentuserinfo.get("assistuserid")%>";
		  eval("document.cform.assistemployeename"+i).value="<%=parentuserinfo.get("assistemployeename")%>";
		 }
		<%
		}
	    %>	
    }
  }
</script>              	
</body>

</html>
	
